from pynput import keyboard
from playsound import playsound
#启用多线程，防止播放和输入卡顿
from threading import Thread
import random
count=0

palylist=['./dama.mp3','./hajimi.mp3']


#监听动作触发回调函数
def play_sound(key):
    global count
    count+=1
    print(key)
    if count%30==0:
        xpy=input("写了那么旧的代码了，要不要听首音乐？-Y/N- :")
        if xpy=="Y":
            i=random.randint(0,len(palylist)-1)
            print(f'Playing {palylist[i]}')
            #创建多线程
            t=Thread(target=playsound,args=(palylist[i],))
            t.start()   #启动线程

listener = keyboard.Listener(on_release=play_sound)  #创建键盘监听对象
listener.start()    #启动监听
listener.join()#结束监听
#我很喜欢Pytonganjuehahahhaooihihihijjojjjoojjoojojjojjhhuhhihhihhihihihhhiihihihiih
#jjijpojh
#
# hih
#
# joojojjojojojojojojojojojjjjo  ijihji                 m    m
# ojoihoihiopjojojojoj
# ojojoooooojojohioj
# jjojojiuhhhhhhhk
# jooojoojjoojijhhoohhioiu
# hjjoojojojojojojojoo
# jojojojojoiuuguoiohhhihujijihji
# huiiooookoojopjjoojoppjoojjojoh